package raceReservationServer.loginGateway;

import raceReservationServer.loginGateway.proxies.AuthorizationWSStub;
import raceReservationServer.loginGateway.proxies.AuthorizationWSStub.Runner;

public class AuthWSGateway implements IAuthorizeGateway {

	/**
	 * Add your code to invoke the Authorization WS here Remember you must use
	 * the stub generated in the proxies package in order to invoke the WS. On
	 * the other hand, REMEMBER that you must catch the generic exception
	 * EXCEPTION AND SEE the contained message in order to map it to the
	 * ValidationException
	 * 
	 */
	String serviceUri;
	public AuthWSGateway(String serviceUri) 
	{
		this.serviceUri = serviceUri;
	}

	public RunnerDO login(String user, String pass) throws ValidationException
	{
		RunnerDO runnerDO = null;
		Runner runner = null;
		
        try {
        	
        	AuthorizationWSStub stub = new AuthorizationWSStub(serviceUri);
            runner = stub.login(user,pass); 
            runnerDO = new RunnerDO(runner.getUsername(),runner.getPassword(),runner.getName(),runner.getAge(),runner.getSex());
        }
        catch (Exception e) 
        {
			throw new ValidationException(e.getMessage());
		}
		return runnerDO;
	}
}
